<?php
/**
 * Created by PhpStorm.
 * User: xcx
 * Date: 2017/6/2
 * Time: 10:31
 */
class Controller_Www_Public extends FController
{
    public function getCityAction(){

        $provinceCode = FRequest::getString("pro_code") ? FRequest::getString("pro_code") : "";
        if($provinceCode){
            $list = Service_User::getCity($provinceCode);
            if($list){
                $result = array('status' => 200, "data" => $list);
            }else{
                $result = array("status" => -1 , "error" => "城市数据未查询到");
            }
        }else{
            $result = array("status" => -2 , "error" => "省份id为空");
        }
//        return FResponse::output($result);
        $json = json_encode($result);
        echo "flightHandler($json)";
    }

    /*
     * 小红薯订单提交
     *
     */
    public function userOrderDealAction(){
        $nickname = FRequest::getString("nickname") ? FRequest::getString("nickname") : "";
        $mobile = FRequest::getString("mobile") ? FRequest::getString("mobile") : "";
        $msg = FRequest::getString("msg") ? FRequest::getString("msg") : "";
        $intention = FRequest::getInt("intention") ? FRequest::getInt("intention") : 0;
        $province = FRequest::getString("province") ? FRequest::getString("province") : "";
        $city = FRequest::getString("city") ? FRequest::getString("city") : "";
        $source = FRequest::getString("domain") ? FRequest::getString("domain") : "";
        $address = FRequest::getString("address") ? FRequest::getString("address") : "";
        $c_uid = FRequest::getInt("c_uid") ? FRequest::getInt("c_uid") : 0;
        $s_uid = FRequest::getInt("s_uid") ? FRequest::getInt("s_uid") : 0;

        if (!Service_Public::checkMobile($mobile)) {
            $result = array('status' => -3, 'error' => '手机号不能为空');
//            return FResponse::output($result);
            $json = json_encode($result);
            echo "flightHandler($json)";
            exit();
        }


        $data = array(
            "nickname" => $nickname,
            "mobile" => $mobile,
            "join_intention" => $intention,
            "province" => $province,
            "city" => $city,
            "source" => $source,
            "address" => $address,
            "status" => 1,
            "c_uid" => $c_uid,
            "s_uid" => $s_uid,
            "msg" => $msg,
            "create_time" => date("Y-m-d H:i:s", time())
        );

        FLogger::write(json_encode($data), 'public');


        $table = new FTable('user_order', "", "");
        $ret = $table->insert($data);
        if ($ret) {
            $result = array('status' => 200, 'data' => '提交成功！');
        } else {
            $result = array('status' => -2, 'error' => '提交失败！');
        }

//        return FResponse::output($result);
        $json = json_encode($result);
        echo "flightHandler($json)";
//        FResponse::output($result);
    }

    /*
     * 获取省份信息
     */
    public function getProAction(){
        $data = Service_User::getProvince();
        if(!$data){
            $result = array("status" => -2 , "error" => "省份数据未查询到");
        }else{
            $result = array("status" => 200 , "data" => $data);
        }
        $json = json_encode($result);
        echo "flightHandler($json)";
//        FResponse::output($result);
    }

    public function teAction(){
        $interval=300; //2分钟
        header('Cache-Control:max-age='.$interval);
        header("Expires: " . gmdate("D, d M Y H:i:s",time()+$interval)." GMT");
        header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
        echo 222222;exit();
    }

    function showMessage($message, $msgType, $url = null)
    {
        echo "<script>alert('{$message}');";
        if ($url) echo "location='{$url}';";
        echo "</script>";
    }
}
